package co.com.travelsoft.ati.daos;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import co.com.travelsoft.ati.entities.Paises;
import co.com.travelsoft.ati.utils.FabricaSesionesUtil;

public class PaisesDAO {
	
	public static void crear(Paises paises){
		Session s = FabricaSesionesUtil.getInstancia().getCurrentSession();
		s.save(paises);
	}
	
	public static Paises buscarPorId(Paises paises){
				
		Session sesion = FabricaSesionesUtil.getInstancia().getCurrentSession();
		Transaction trx = sesion.beginTransaction();
		Paises pais =  (Paises)sesion.createQuery("select c from Paises as c where c.codigo = :codigo").
				setParameter("codigo", paises.getCodigo()).uniqueResult();
		trx.commit();
        
        return pais;
		
	}
	
	public static List<Paises> listar(){
		
		Session sesion = FabricaSesionesUtil.getInstancia().getCurrentSession();
    	Transaction trx = sesion.beginTransaction();
    	List<Paises> paises= sesion.createQuery("select c from Paises as c").list();
    	trx.commit();
        return paises;
		
	}
	
	public static void actualizar(Paises paises){
		Session s = FabricaSesionesUtil.getInstancia().getCurrentSession();
		s.update(paises);
	
	}
	
	public static void borrar(Paises paises){
		Session s = FabricaSesionesUtil.getInstancia().getCurrentSession();
		s.delete(paises);
		
	}

}
